package GUI_creator;
import GUI.*;

import javax.swing.JPanel;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.JButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

@SuppressWarnings("serial")
public class MainPanelCreator extends JPanel {
 
	public MainPanelCreator() {
		
		SpinnerNumberModel sm_size = new SpinnerNumberModel(5, 5, 15, 1);
		
		SpinnerNumberModel sm_flows= new SpinnerNumberModel(5, 1, 15, 1);
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{152, 93, 60, 0};
		gridBagLayout.rowHeights = new int[]{48, 22, 40, 20, 20, 20, 36, 23, 0, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		JLabel lblFlowfreeCreator = new JLabel("FLOWFREE");
		lblFlowfreeCreator.setFont(new Font("Tahoma", Font.PLAIN, 18));
		GridBagConstraints gbc_lblFlowfreeCreator = new GridBagConstraints();
		gbc_lblFlowfreeCreator.anchor = GridBagConstraints.NORTH;
		gbc_lblFlowfreeCreator.insets = new Insets(0, 0, 5, 0);
		gbc_lblFlowfreeCreator.gridwidth = 2;
		gbc_lblFlowfreeCreator.gridx = 1;
		gbc_lblFlowfreeCreator.gridy = 1;
		add(lblFlowfreeCreator, gbc_lblFlowfreeCreator);
		
		JLabel lblCriadorDeTabuleiros = new JLabel("Criador de Tabuleiros");
		lblCriadorDeTabuleiros.setFont(new Font("Tahoma", Font.PLAIN, 15));
		GridBagConstraints gbc_lblCriadorDeTabuleiros = new GridBagConstraints();
		gbc_lblCriadorDeTabuleiros.gridwidth = 2;
		gbc_lblCriadorDeTabuleiros.insets = new Insets(0, 0, 5, 0);
		gbc_lblCriadorDeTabuleiros.gridx = 1;
		gbc_lblCriadorDeTabuleiros.gridy = 2;
		add(lblCriadorDeTabuleiros, gbc_lblCriadorDeTabuleiros);
		
		JLabel lblRowsColumns = new JLabel("Linhas/Colunas");
		GridBagConstraints gbc_lblRowsColumns = new GridBagConstraints();
		gbc_lblRowsColumns.insets = new Insets(0, 0, 5, 5);
		gbc_lblRowsColumns.gridx = 1;
		gbc_lblRowsColumns.gridy = 4;
		add(lblRowsColumns, gbc_lblRowsColumns);
		final JSpinner spinner_size = new JSpinner(sm_size);
		GridBagConstraints gbc_spinner_size = new GridBagConstraints();
		gbc_spinner_size.anchor = GridBagConstraints.NORTH;
		gbc_spinner_size.insets = new Insets(0, 0, 5, 0);
		gbc_spinner_size.gridx = 2;
		gbc_spinner_size.gridy = 4;
		add(spinner_size, gbc_spinner_size);
		
		
		JLabel lblFlows = new JLabel("Flows");
		GridBagConstraints gbc_lblFlows = new GridBagConstraints();
		gbc_lblFlows.insets = new Insets(0, 0, 5, 5);
		gbc_lblFlows.gridx = 1;
		gbc_lblFlows.gridy = 5;
		add(lblFlows, gbc_lblFlows);
		
		final JSpinner spinner_flows = new JSpinner(sm_flows);
		GridBagConstraints gbc_spinner_flows = new GridBagConstraints();
		gbc_spinner_flows.anchor = GridBagConstraints.NORTH;
		gbc_spinner_flows.insets = new Insets(0, 0, 5, 0);
		gbc_spinner_flows.gridx = 2;
		gbc_spinner_flows.gridy = 5;
		add(spinner_flows, gbc_spinner_flows);
	
		GridBagConstraints gbc_btnCreate = new GridBagConstraints();
		gbc_btnCreate.insets = new Insets(0, 0, 5, 0);
		gbc_btnCreate.anchor = GridBagConstraints.NORTH;
		gbc_btnCreate.gridwidth = 2;
		gbc_btnCreate.gridx = 1;
		gbc_btnCreate.gridy = 7;
		
		JButton btnCreate = new JButton("Criar");
		btnCreate.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent arg0) {
				int size = (int) spinner_size.getValue();
				int flows = (int) spinner_flows.getValue();
				GUI.frame.setContentPane(new CreatorPanel(size, flows));
				GUI.frame.setBounds(100, 100, 800, 600);
				((JPanel)GUI.frame.getContentPane()).revalidate();
				GUI.frame.repaint();
			}
		});
		add(btnCreate, gbc_btnCreate);
		
		JButton btnNewButton = new JButton("Voltar Atr\u00E1s");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				GUI.frame.setContentPane(new MainPanel());
				((JPanel)GUI.frame.getContentPane()).revalidate();
				GUI.frame.repaint();
			}
		});
		GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
		gbc_btnNewButton.gridwidth = 2;
		gbc_btnNewButton.insets = new Insets(0, 0, 0, 5);
		gbc_btnNewButton.gridx = 1;
		gbc_btnNewButton.gridy = 8;
		add(btnNewButton, gbc_btnNewButton);
		

	}
}
